package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/14 10:57
 */
public class LS_Offer_03 {
    public int findRepeatNumber(int[] nums) {
        int index = 0;
        while (index < nums.length) {
            //
            if (index != nums[index]) {
                //判断
                if (nums[index] == nums[nums[index]]) {
                    return nums[index];
                } else {
                    swap(nums,index,nums[index]);
                }
            } else {
                index++;
            }
        }
        return 0;
    }
    public void swap(int[] nums,int a, int b) {
        int temp = nums[a];
        nums[a] = nums[b];
        nums[b] = temp;
    }
}
